<?php
#基础函数
include_once('_path.php');

include_once(_ROOTPATH."backend/includes/init.php");

#count user
$sql = "SELECT count(*) as total FROM user";
$rs = $database->queryFirst($sql, rand(360,720));
$total_user = $rs["total"];
#count vote
$sql = "SELECT count(*) as total FROM vote";
$rs = $database->queryFirst($sql, 360);
$total_vote = $rs["total"];
#count comment
$sql = "SELECT count(*) as total FROM vote_comment";
$rs = $database->queryFirst($sql, 360);
$total_comment = $rs["total"];
#count thumb file
$sql = "SELECT count(*) as total FROM thumb_file";
$rs = $database->queryFirst($sql, 360);
$total_thumb = $rs["total"];
#Members online
$sql = "SELECT count(*) as total FROM session where user_id>0 and ("._CONST_TIMENOW." - `lastactivity`) < 1440";
$rs = $database->queryFirst($sql);
$total_members_online = $rs["total"];
#Guest online
$sql = "SELECT count(*) as total FROM session where user_id=0 and ("._CONST_TIMENOW." - `lastactivity`) < 1440";
$rs = $database->queryFirst($sql);
$total_guest_online = $rs["total"];

$css = array('index', 'table');
$js = array();

add_log('show', 'index');

include_once(_ROOTPATH."backend/layout/_header.php");
?>
<div id="path">
	<ul>
		<li><a href="<?php echo _CONST_WEB_URL ?>"><?php echo _CONST_WEB_NAME?></a></li>
		<li><a href="<?php echo _CONST_BACKEND_URL ?>">Backend</a></li>
		<li>Dashboard</li>
	</ul>
	<a href="<?=_CONST_BACKEND_URL?>logout.php" class="r" style="margin:2px 10px"><span class="logout">Logout</span></a>
</div>

<div id="content">

	<ul id="submenu">
		<li class="current"><a href="<?php echo _CONST_BACKEND_URL ?>index.php" class="button"><span class="dashboard">Dashboard</span></a></li>
		<li><a href="<?php echo _CONST_BACKEND_URL ?>vote/index.php" class="button"><span class="manga">Vote</span></a></li>
		<li><a href="<?php echo _CONST_BACKEND_URL ?>user/index.php" class="button"><span class="group">User</span></a></li>
		<li><a href="<?php echo _CONST_BACKEND_URL ?>thumb/index.php" class="button"><span class="list">Thumb</span></a></li>
       <li><a href="<?php echo _CONST_BACKEND_URL ?>admin/index.php" class="button"><span class="setting">Admin</span></a></li>
       <li><a href="<?php echo _CONST_BACKEND_URL ?>logs/index.php" class="button"><span class="log">Logs</span></a></li>
	</ul>
  <span style="margin:7px 10px 2px 50px;" class="l">Current User:<?php echo $_SESSION['bname']?>&nbsp;&nbsp;<?php echo gmdate('D M j, Y h:ia T', _CONST_TIMENOW) ?></span>

		<div class="border cr">
			<!-- Statistics -->
			<div style="float:left">
      <h2 style="margin:10px;">Statistics</h2>
			<table cellspacing="4" class="info l cr">
				<tr>
					<td><b>Total User</b></td>
					<td class="rt"><?php echo $total_user?></td>
				</tr>
				<tr>
					<td><b>Total Vote</b></td>
					<td class="rt">
					<?php echo $total_vote?>
					</td>
				</tr>
				<tr>
					<td><b>Total Comment</b></td>
					<td class="rt"><?php echo $total_comment ?></td>
				</tr>
				<tr>
					<td><b>Total Thumb</b></td>
					<td class="rt"><?php echo $total_thumb ?></td>
				</tr>
				<tr>
					<td><b>Members online</b></td>
					<td class="rt"><?php echo $total_members_online ?></td>
				</tr>
              <tr>
					<td><b>Guest online</b></td>
					<td class="rt"><?php echo $total_guest_online ?></td>
              </tr>
			</table>
      </div>
	  <div class="cr"></div>
</div>
</div>
<?php
include_once(_ROOTPATH."backend/layout/_footer.php");
?>